package org.moflon.moca;

import java.io.File;

import org.apache.log4j.BasicConfigurator;
import org.moflon.moca.text.unparser.HtmlUnparserAdapter;
import org.moflon.moca.text.unparser.TextUnparserAdapter;
import org.moflon.util.eMoflonEMFUtil;

import BoardGame.Board;
import BoardGame.BoardGameFactory;
import BoardGame.BoardGamePackage;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.MocaTreePackage;
import Rules.RulesPackage;

public class MocaMain {

	private static CodeAdapter codeAdapter;

	private static final String inputModel = "instances/in/board.xmi";
	
	public static void main(String[] args) {
		BasicConfigurator.configure();

		// Register parsers and unparsers
		codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
		codeAdapter.getUnparser().add(new TextUnparserAdapter());
		codeAdapter.getUnparser().add(new HtmlUnparserAdapter());

		// Perform model-to-tree
		RulesPackage.eINSTANCE.getName();
		Board board = (Board) eMoflonEMFUtil.loadModel(BoardGamePackage.eINSTANCE, inputModel, null);

		BoardGame.CodeAdapter transformer = BoardGameFactory.eINSTANCE.createCodeAdapter();
		MocaTree.File file = transformer.transformModelToText(board);

		eMoflonEMFUtil.saveModel(MocaTreePackage.eINSTANCE, file, "instances/out/tree.xmi");

		// Perform tree-to-text
		file.setName("board.txt");
		codeAdapter.unparseFile(file, new File("instances/out"));
		
		// Perform tree-to-html
		file.setName("board.html");
		codeAdapter.unparseFile(file, new File("instances/out"));
	}
}